#include "Skeleton2.h"

#include "MathUtil.h"


Skeleton2::Skeleton2(float lenArm, float lenLeg)
{
    // Torso
    this->torso = new Bone2((short)TORSO, Math::Vector3(0.0f, 0.0f, 0.0f), 2, 0.5f, NONE);

    // Left arm
    this->leftArm0 = new Bone2((short)LEFT_ARM0, Math::Vector3(0.0f, 1.0f, 0.0f), lenArm/2.0f, 0.0f, LEFT);
    this->leftArm1 = new Bone2((short)LEFT_ARM1, Math::Vector3(0.0f, 0.0f, 0.0f), lenArm/2.0f, 0.0f, LEFT);

    // Right arm
    this->rightArm0 = new Bone2((short)RIGHT_ARM0, Math::Vector3(0.0f, 1.0f, 0.0f), lenArm/2.0f, 0.0f, RIGHT);
    this->rightArm1 = new Bone2((short)RIGHT_ARM1, Math::Vector3(0.0f, 0.0f, 0.0f), lenArm/2.0f, 0.0f, RIGHT);

    // Left leg
    this->leftLeg0 = new Bone2((short)LEFT_LEG0, Math::Vector3(0.0f, -1.0f, 0.0f), lenLeg/2.0f, 0.0f, LEFT);
    this->leftLeg1 = new Bone2((short)LEFT_LEG1, Math::Vector3(0.0f, 0.0f, 0.0f), lenLeg/2.0f, 0.0f, LEFT);

    // Right leg
    this->rightLeg0 = new Bone2((short)RIGHT_LEG0, Math::Vector3(0.0f, -1.0f, 0.0f), lenLeg/2.0f, -0.1f, RIGHT);
    this->rightLeg1 = new Bone2((short)RIGHT_LEG1, Math::Vector3(0.0f, 0.0f, 0.0f), lenLeg/2.0f, 0.0f, RIGHT);

    // Connect skeleton
    this->leftArm0->addChildBone(this->leftArm1);
    this->rightArm0->addChildBone(this->rightArm1);

    this->leftLeg0->addChildBone(this->leftLeg1);
    this->rightLeg0->addChildBone(this->rightLeg1);

    // All parts to torso
  //  this->torso->addChildBone(this->leftArm0);
    this->torso->addChildBone(this->rightArm0);

  //  this->torso->addChildBone(this->leftLeg0);
    this->torso->addChildBone(this->rightLeg0);
}

Skeleton2::~Skeleton2() {
    delete this->torso;
}

void Skeleton2::draw() {
    // draw code
   /* glTranslatef(position.x, position.y, position.z);
    glLineWidth(3.0f);
    glColor3f(1.0f, 0.0f, 0.0f);

    glBegin(GL_LINE);
        glVertex3f(position.x, position.y, position.z);
        glVertex3f(end.x, end.y, end.z);
    glEnd();*/

    this->torso->draw();


    //SceneNode::draw();
}

void Skeleton2::update() {

    // update code

    //SceneNode::update();
}

void Skeleton2::animate() {

    // update code

    //SceneNode::update();
}
